package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResultVo;
import com.tanhua.server.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Description: test
 * @Create by: JJ菜菜
 * @Date: 2021/12/3 15:39
 */

/**
 *  评论列表查询
 */
@RestController
@RequestMapping("/comments")
public class CommentsController {

    @Autowired
    private CommentsService commentsService;

    /**
     * 评论列表
     * @param movementId
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping
    public ResponseEntity comments(String movementId,
                                   @RequestParam(defaultValue = "10") Integer page,
                                   @RequestParam(defaultValue = "1") Integer pageSize){

        PageResultVo vo = commentsService.comments(movementId, page, pageSize);
        return ResponseEntity.ok(vo);
    }

    /**
     * 保存评论
     * @param map
     * @return
     */
    @PostMapping
    public ResponseEntity saveComments(@RequestBody Map map){

        String movementId = (String) map.get("movementId");
        String comment = (String) map.get("comment");

        commentsService.saveComments(movementId, comment);
        return ResponseEntity.ok(null);
    }

}
